<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>医生列表主页</title>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link href="css/style1.css" rel="stylesheet">
    <link href="/css/style.css" rel="stylesheet">
    <script src="js/jquery.min.js"></script>
    <script src="js/lodash.min.js"></script> <!-- 引入 Lodash 库（如果在删除操作中需要防抖等功能可使用） -->
    <style>
        .btn2{
            color: #eec4a0;
            background: #fdf6ec;
            border: 1px solid #f8e6cb;
        }
        .btn2:hover,.btn2:focus{
            color: #fff !important;
            background-color: #eec4a0 !important;
            border-color: #eec4a0 !important;
        }
        .cancle{
            color: #eec4a0;
        }
        .cancle:hover,.cancle:focus{
            color: #fff !important;
        }
    </style>
</head>
<body>
<div th:insert="~{admin/header1}"></div>
<main id="main">
    <section class="breadcrumbs">
        <div class="container">
            <div class="d-flex justify-content-between align-items-center">
                <ol>
                    <li><a href="#">首页</a></li>
                    <li><a href="#">浏览医生</a></li>
                </ol>
            </div>
        </div>
    </section>
    <section class="inner-page">
        <div class="container" id="contentArea">
            <div class="card">
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table text-center justify-content-center">
                        <tbody class="text-center me-auto">
                        <tr>
                            <th>医生编号</th>
                            <th>医生姓名</th>
                            <th>所在科室</th>
                            <th>职位</th>
                            <th>操作</th>
                        </tr>
                        <tr th:each="doctor : ${allDoctors}" class="text-center me-auto">
                            <td th:text="${doctor.id}"></td>
                            <td th:text="${doctor.name}"></td>
                            <td th:text="${doctor.dName}"></td>
                            <td th:text="${doctor.job}"></td>
                            <td>
                                <form th:action="@{/doctor/detail(id=${doctor.id})}" method="post" style="display: inline">
                                    <button type="submit" class="btn btn-sm">详情</button>
                                </form>
                                <form th:action="@{/doctor/toUpdate(id=${doctor.id})}" method="post" style="display:inline">
                                    <button type="submit" class="btn btn1 btn-sm">编辑</button>
                                </form>
                                <a th:href="'javascript:deleteDoctor('+${doctor.id}+')'" class="btn btn2 btn-sm" style="margin-left: 20px;">删除</a>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="5" style="border: none;">
                                <ul class="pagination justify-content-center">
                                    <li class="page-item" th:if="${currentPage}!= 1">
                                        <a class="page-link"
                                           th:href="@{/doctor/selectAllDoctorsByPage(currentPage=${currentPage - 1})}">上一页</a>
                                    </li>
                                    <li class="page-item disabled">
                                        <a class="page-link" href="#">第<span
                                                th:text="${currentPage}"></span>页</a>
                                    </li>
                                    <li class="page-item disabled">
                                        <a class="page-link" href="#">共<span
                                                th:text="${totalPage}"></span>页</a>
                                    </li>
                                    <li class="page-item" th:if="${currentPage}!= ${totalPage}">
                                        <a class="page-link"
                                           th:href="@{/doctor/selectAllDoctorsByPage(currentPage=${currentPage + 1})}">下一页</a>
                                    </li>
                                </ul>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </section>
</main>
<script type="text/javascript" th:inline="javascript">
    function deleteDoctor(tid) {
        $.ajax({
            url: [[@{/doctor/delete}]],
        type: "post",
            data: {
            id: tid
        },
        success: function (obj) {
            if (obj == "no") {
                alert("该医生有关联不允许删除！");
            } else {
                alert(obj);
                location.reload();
            }
        },
        error: function () {
            alert("处理异常！");
        }
    });
    }
</script>
</body>

</html>